<template>
  <a-modal
    title="详情"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @cancel="handleCancel"
  >
     <template slot="footer">
        <a-button key="back" @click="handleCancel">
          取消
        </a-button>
        <a-button key="submit" type="primary"  @click="handleSubmit">
          打印
        </a-button>
  </template>
    <a-spin :spinning="confirmLoading">
      <a-row>
        <a-col :span="24"><h2>小計：<span class="red">{{ data.subtotal }}元</span></h2></a-col>
        <a-col :span="24"><h2>實收：<span  class="red">{{ data.receiveAmount }}元</span></h2></a-col>
        <a-col :span="24">[{{ data.qs }}] - {{ data.roomName }} - {{ data.name }} - {{ data.phone }}</a-col>
      </a-row>
       <a-row>
        <a-col :span="24">流水號：{{ data.no }}</a-col>
        <a-col :span="24">收租日：{{ data.rentedDay }}</a-col>
        <a-col :span="24">賬單週期：{{ data.rentStartDate }}-{{ data.rentEndDate }}</a-col>
        <a-col :span="24">到賬日期：{{ data.receiveDate }}</a-col>
        <a-col :span="24">收款方式：{{ statusFkfsFilter(data.collectionType) }}</a-col>
      </a-row>
      <a-divider />
      <a-row>
        <a-col :span="24"><h3>費用明細</h3></a-col>
      </a-row>
      <a-row>
        <a-col :span="24" v-for="(item,index) in data.fyxx" :key="index">
          {{ item.rentAmountName }}：{{ item.amount }}元
        </a-col>
      </a-row>
      <a-divider />
      <a-row>
        <a-col :span="24"><h3>臨時收入</h3></a-col>
      </a-row>
      <a-row>
        <a-col :span="24" v-for="(item,index) in data.lssr" :key="index">
          {{ item.rentAmountName }}：{{ item.amount }}元
        </a-col>
      </a-row>
      <a-divider />
      <a-row>
        <a-col :span="24"><h3>臨時支出</h3></a-col>
      </a-row>
      <a-row>
        <a-col :span="24" v-for="(item,index) in data.lszc" :key="index">
          {{ item.rentAmountName }}：{{ item.amount }}元
        </a-col>
      </a-row>
      <a-divider />
      <a-row>
        <a-col :span="24">經辦人：{{ data.userName }}</a-col>
        <a-col :span="24">操作時間：{{ data.createTime }}</a-col>
      </a-row>
    </a-spin>
   <print-bill-detail ref="printBillDetail"/>
  </a-modal>
</template>

<script>
  import moment from 'moment'
  import { busMeansOfTransactionList } from '@/api/modular/main/busmeansoftransaction/busMeansOfTransactionManage'
  import { getWaterBillById } from '@/api/modular/main/housebill/houseBillManage'
  import printBillDetail from '../housebill/printBillDetail.vue'
  export default {
    components: {
      printBillDetail
    },
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        sourceData: [],
        transactionData: [],
        auditFlagData: [],
        auditTimeDateString: '',
        visible: false,
        confirmLoading: false,
        data: {}
      }
    },
    methods: {
      moment,
      // 初始化方法
      edit (id) {
        this.initData(id)
        this.visible = true
        const sourceOption = this.$options
        this.sourceData = sourceOption.filters['dictData']('bill_water_source')
      },
      initData(id) {
         getWaterBillById(id).then((res) => {
          if (res.code === 200) {
            this.data = res.data
          } else {
            this.$message.error(res.msg)
          }
        })
        busMeansOfTransactionList().then((res) => {
          if (res.code === 200) {
            this.transactionData = res.data
          } else {
            this.$message.error(res.msg)
          }
        })
      },
      statusFkfsFilter (id) {
        // eslint-disable-next-line eqeqeq
        const values = this.transactionData.filter(item => item.id == id)
        if (values.length > 0) {
          return values[0].name
        }
      },
      handleSubmit () {
        this.$refs.printBillDetail.edit(this.data.id)
        this.handleCancel()
      },
      handleCancel () {
        this.visible = false
        this.data = {}
      }
    }
  }
</script>

<style lang="less" scoped>
.red{
  color: red;
}
</style>
